<!--
 *Author：jxx
 *Contact：283591387@qq.com
 *业务请在@/extension/workorder/report/ysl_production_report.jsx或ysl_production_report.vue文件编写
 *新版本支持vue或【表.jsx]文件编写业务,文档见:https://v3.volcore.xyz/docs/view-grid、https://v3.volcore.xyz/docs/web
 -->
<template>
  <view-grid
    ref="grid"
    :columns="columns"
    :detail="detail"
    :details="details"
    :editFormFields="editFormFields"
    :editFormOptions="editFormOptions"
    :searchFormFields="searchFormFields"
    :searchFormOptions="searchFormOptions"
    :table="table"
    :extend="extend"
    :onInit="onInit"
    :onInited="onInited"
    :searchBefore="searchBefore"
    :searchAfter="searchAfter"
    :addBefore="addBefore"
    :updateBefore="updateBefore"
    :rowClick="rowClick"
    :modelOpenBefore="modelOpenBefore"
    :modelOpenAfter="modelOpenAfter"
  >
    <!-- 自定义组件数据槽扩展，更多数据槽slot见文档 -->
    <template #gridHeader> </template>
  </view-grid>

  <!--将select-custom这段代码放在view-grid标签后面 -->
  <!-- 弹出框(选择数据) -->
  <select-custom ref="customRef" @onSelectCustom="onSelectCustom"></select-custom>
</template>
<script setup lang="jsx">
import extend from '@/extension/workorder/report/ysl_production_report.jsx'
import viewOptions from './ysl_production_report/options.js'
import { ref, reactive, getCurrentInstance, watch, onMounted } from 'vue'
const grid = ref(null)
const { proxy } = getCurrentInstance()
//http请求，proxy.http.post/get
const {
  table,
  editFormFields,
  editFormOptions,
  searchFormFields,
  searchFormOptions,
  columns,
  detail,
  details
} = reactive(viewOptions())

//生成对象属性初始化
//直接引用生成的页面(也可以单独用table配置，单独配置下见下面【编辑弹出框明细表选择数据】)
//将本地的onInit代码去掉，替换下面的这一段整代码
import SelectCustom from '@/views/workorder/report/ysl_production_reportSelect.vue'
let gridRef
const onInit = async ($vm) => {
  gridRef = $vm
  const option = gridRef.getFormOption('Auditor')
  option.readonly = true
  option.extra = {
    icon: 'el-icon-zoom-out', //显示图标
    text: '选择', //显示文本
    style: 'color: #3a8ee6;font-size: 13px;cursor: pointer;',
    //触发事件
    click: (item) => {
      customRef.value.open()
    }
  }
}
const customRef = ref()
//生成对象属性初始化后,操作明细表配置用到
const onInited = async () => {}
const searchBefore = async (param) => {
  //界面查询前,可以给param.wheres添加查询参数
  //返回false，则不会执行查询
  return true
}
const searchAfter = async (rows, result) => {
  return true
}
const addBefore = async (formData) => {
  //新建保存前formData为对象，包括明细表，可以给给表单设置值，自己输出看formData的值
  return true
}
const updateBefore = async (formData) => {
  //编辑保存前formData为对象，包括明细表、删除行的Id
  return true
}
const rowClick = ({ row, column, event }) => {
  //查询界面点击行事件
  // grid.value.toggleRowSelection(row); //单击行时选中当前行;
}
const modelOpenBefore = async (row) => {
  //弹出框打开后方法
  return true //返回false，不会打开弹出框
}
const modelOpenAfter = (row) => {
  //弹出框打开后方法,设置表单默认值,按钮操作等
}
//监听表单输入，做实时计算
//watch(() => editFormFields.字段,(newValue, oldValue) => {	})
//对外暴露数据
defineExpose({})
//选择客户回调
const onSelectCustom = (rows) => {
  editFormFields.Auditor = rows[0].UserName
  //这里还可以给其他字段设置值editFormFields.字段=
}
</script>
<style lang="less" scope></style>
